package com.yanqu.road.server.pb;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.yanqu.road.entity.activity.chefduel.ChefDuelData;
import com.yanqu.road.entity.activity.chefduel.ChefDuelFinishFood;
import com.yanqu.road.entity.activity.chefduel.ChefDuelFood;
import com.yanqu.road.entity.activity.chefduel.process2.ChefDuel2Dish;
import com.yanqu.road.pb.chefduel.ChefDuelProto;

import java.util.Map;

public class ChefDuelPb {

	public static ChefDuelProto.ChefDuel2SelfDishRespMsg.Builder parseSelfDishTableMsg(ChefDuelData chefDuelData){
		ChefDuelProto.ChefDuel2SelfDishRespMsg.Builder msg = ChefDuelProto.ChefDuel2SelfDishRespMsg.newBuilder();
		msg.setRet(0);
		return msg;
	}

	public static ChefDuelProto.ChefDuel2SelfDishSyncMsg.Builder parseSelfDishTableSync(ChefDuelData chefDuelData){
		ChefDuelProto.ChefDuel2SelfDishSyncMsg.Builder msg = ChefDuelProto.ChefDuel2SelfDishSyncMsg.newBuilder();
		msg.setJoin(chefDuelData.isAble()?1:0);
		msg.setDishId(chefDuelData.getDishId());
		msg.setPickTimes(chefDuelData.getProcess());
		msg.setHp(chefDuelData.getHp());
		msg.setIntegral(chefDuelData.getAllIntegral());
		msg.setHpTime((int)(chefDuelData.getHpTime()/1000));
		msg.setIsWorship(chefDuelData.isWorship());
		msg.setBuffNum(chefDuelData.getBuffNum());
		Map<Integer, ChefDuel2Dish> finishDishMap = JSON.parseObject(chefDuelData.getFinishFoodData(), new TypeReference<Map<Integer, ChefDuel2Dish>>() {});
		for(ChefDuel2Dish finishFood : finishDishMap.values()){
			ChefDuelProto.ChefDuel2DishTempMsg.Builder tempFood = ChefDuelProto.ChefDuel2DishTempMsg.newBuilder();
			tempFood.setId(finishFood.getIndex());
			tempFood.setDishId((finishFood.getDishId()));
			tempFood.setStatus(finishFood.getStatus());
			tempFood.setIntegral(finishFood.getIntegral());
			tempFood.setTableId(finishFood.getTableId());
			tempFood.setMakeIntegral(finishFood.getMakeIntegral());
			tempFood.setMakeAddition(finishFood.getMakeAddition());
			msg.addDishList(tempFood);
		}
		return msg;
	}


	public static ChefDuelProto.ChefDuel3SelfDataSyncMsg.Builder parseSelfBanquetTableSync(ChefDuelData chefDuelData){
		ChefDuelProto.ChefDuel3SelfDataSyncMsg.Builder msg = ChefDuelProto.ChefDuel3SelfDataSyncMsg.newBuilder();
		msg.setActivityId(chefDuelData.getActivityId());
		msg.setJoin(chefDuelData.isAble()?1:0);
		msg.setIntegral(chefDuelData.getAllIntegral());
		msg.setIsWorship(chefDuelData.isWorship());
		msg.setSupportCamp(chefDuelData.getSupportCampId());
		return msg;
	}
}
